package js;

import java.util.Scanner;

public class q特殊日期 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //数字之和。请问从1900年1月1日至9999年12月31日，总共有多少天，年份的数位数字之和等于月的数位数字之和加日的数位数字之和。
        System.out.println(count());
        scan.close();
    }

    static long count() {
        long count = 0;
        int year = 1900;
        int month = 1;
        int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int day = 1;
        while (year <= 9999) {
            int yearSum = 0;
            int monthSum = 0;
            int daySum = 0;

            //闰年判断
            if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                days[1] = 29;
            }else {
                days[1] = 28;
            }
            if(day > days[month - 1]) {
                day = 1;
                month++;
                if(month > 12) {
                    month = 1;
                    year++;
                    if(year > 9999) {
                        break;
                    }
                }
            }
            yearSum = sum(year);
            monthSum = sum(month);
            daySum = sum(day);
            if (yearSum == monthSum + daySum) {
                count++;
            }
            day++;


        }

        return count;
    }

    static int sum(int n) {
        int sum = 0;
        while (n > 0) {
            sum += n % 10;
            n = n / 10;
        }
        return sum;
    }
}
